package com.meteor.controller;

import com.meteor.framework.common.base.ResponseData;
import com.meteor.framework.common.utils.PageResult;
import com.meteor.framework.operatelog.annotations.OperateLog;
import com.meteor.framework.operatelog.enums.OperateTypeEnum;
import com.meteor.query.CommunityQuery;
import com.meteor.query.OwnerRoomQuery;
import com.meteor.service.CommunityService;
import com.meteor.service.OwnerRoomService;
import com.meteor.vo.CommunityVO;
import com.meteor.vo.OwnerRoomVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lynn
 * @date 2024/1/22
 */

@RestController
@RequestMapping("new/ownerRoom")
@Tag(name = "业主绑定房屋管理")
@AllArgsConstructor
public class OwnerRoomController {

    private final OwnerRoomService ownerRoomService;


    @GetMapping("page")
    @Operation(summary = "分页查询")
//    @PreAuthorize("hasAuthority('sys:publicity:page')")
    public ResponseData page(@ParameterObject @Valid OwnerRoomQuery query) {

        PageResult<OwnerRoomVO> page = ownerRoomService.page(query);

        return ResponseData.success(page);
    }

    @GetMapping("allList")
    @Operation(summary = "全部查询")
//    @PreAuthorize("hasAuthority('sys:publicity:all')")
    public ResponseData allList(OwnerRoomQuery query) {

        List<OwnerRoomVO> page = ownerRoomService.getList(query);

        return ResponseData.success(page);
    }


    @GetMapping("{id}")
    @Operation(summary = "信息")
//    @PreAuthorize("hasAuthority('sys:publicity:info')")
    public ResponseData get(@PathVariable("id") String id) {
        return ResponseData.success("查询成功", ownerRoomService.get(id));
    }

    @PostMapping
    @Operation(summary = "保存")
    @OperateLog(type = OperateTypeEnum.INSERT)
//    @PreAuthorize("hasAuthority('sys:publicity:save')")
    public ResponseData save(@RequestBody @Valid OwnerRoomVO vo) {
        ownerRoomService.save(vo);

        return ResponseData.success("新增成功");
    }

    @PutMapping
    @Operation(summary = "修改")
    @OperateLog(type = OperateTypeEnum.UPDATE)
//    @PreAuthorize("hasAuthority('sys:publicity:update')")
    public ResponseData update(@RequestBody @Valid OwnerRoomVO vo) {
        ownerRoomService.update(vo);

        return ResponseData.success("修改成功");
    }

    @DeleteMapping("{id}")
    @Operation(summary = "删除")
    @OperateLog(type = OperateTypeEnum.DELETE)
//    @PreAuthorize("hasAuthority('sys:publicity:delete')")
    public ResponseData delete(@PathVariable("id") String id) {
        ownerRoomService.delete(id);

        return ResponseData.success("删除成功");
    }

    @GetMapping("user/{userId}")
    @Operation(summary = "信息")
    public ResponseData getUserId(@PathVariable("userId") String userId) {
        return ResponseData.success("查询成功", ownerRoomService.getUserId(userId));
    }


    @GetMapping("userBind/{userId}")
    @Operation(summary = "信息")
    public ResponseData getBindUserId(@PathVariable("userId") String userId) {
        return ResponseData.success("查询成功", ownerRoomService.getBindUserId(userId));
    }

    @GetMapping("userAwaitCount/{userId}")
    @Operation(summary = "我的待办统计")
    public ResponseData getAwaitCountUserId(@PathVariable("userId") String userId) {
        return ResponseData.success("查询成功", ownerRoomService.getAwaitCountUserId(userId));
    }

    @GetMapping("userAwait/{userId}")
    @Operation(summary = "我的待办")
    public ResponseData getAwaitUserId(@PathVariable("userId") String userId) {
        return ResponseData.success("查询成功", ownerRoomService.getAwaitUserId(userId));
    }

    @PostMapping("/audit")
    @Operation(summary = "审批")
    @OperateLog(type = OperateTypeEnum.UPDATE)
    public ResponseData audit(@RequestBody @Valid OwnerRoomVO vo) {
        ownerRoomService.audit(vo);
        return ResponseData.success("审批完成");
    }


    @GetMapping("relieve/{id}")
    @Operation(summary = "解除绑定")
    public ResponseData relieve(@PathVariable("id") String id) {
        ownerRoomService.relieve(id);
        return ResponseData.success("解绑成功");
    }
}
